﻿create PROCEDURE Sync.SP_LoanIntstallmentWarnings_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[LoanIntstallmentWarningID],
		g.[LoanExecutionInstallmentID],g.[WarningDate],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[LoanIntstallmentWarnings] g RIGHT JOIN Sync.LoanIntstallmentWarnings_Tracking t  
    ON t.LoanIntstallmentWarningID = g.LoanIntstallmentWarningID 
    join LoanExecutionInstallments lei on lei.LoanExecutionInstallmentID = g.LoanExecutionInstallmentID
	join LoanExecution le on le.LoanExecutionID = lei.LoanExecutionID
	join CustomerLoans cl
	on le.LoanID = cl.LoanID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
	AND ((@FilterdColumn IS NULL) OR (cl.CommitteeID = @FilterdColumn))
    END











